package net.zjitc.queue;

public class ArraysQueue<T> implements MyQueue <T>{
    private int MaxSize = 10;
    private Object[] arr = new Object[MaxSize];
    private int rear=0;
    private int front=0;
    //判断是否为空
    @Override
    public boolean isEmpty() {

        return rear == front?true:false;
    }

    //入队
    @Override
    public boolean add(T x) {
        arr[rear] = x;
        rear = (rear+1)%MaxSize;
        return true;
    }

    //返回队头
    @Override
    public T peek() {
        return (T) arr[front];
    }

    //出队
    @Override
    public T poll() {
        T var = (T)arr[front];
        arr[front] = null;
        front = (front+1)%MaxSize;
        return var;
    }

    @Override
    public int size() {
        return (rear - front + MaxSize)%MaxSize;
    }
    public boolean isFull(){
        return (rear+1)%MaxSize == front?true:false;
    }
}
